package com.dsl.tms.controller;

import com.dsl.tms.entity.request.MsgId;
import com.dsl.tms.entity.response.*;
import com.dsl.tms.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RefreshScope
@RestController
@RequestMapping(path = "/message")
@CrossOrigin("${cross_origin.user_client_admin}")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @RequestMapping(path = "/init",method = RequestMethod.GET)
    public @ResponseBody MessageInitMap init(@RequestParam("token") String token){

        return messageService.init(token);
    }

    @RequestMapping(path = "/content",method = RequestMethod.GET)
    public @ResponseBody ContentMap content(@RequestParam("msg_id") int message_id,@RequestParam("token") String token){
        return messageService.getContentByMsgId(message_id,token);
    }

    @RequestMapping(path = "/has_read",method = RequestMethod.POST)
    public @ResponseBody HasReadMap has_read(@RequestBody MsgId msgId){
        return messageService.has_read(msgId.getMsg_id(),msgId.getToken());
    }

    @RequestMapping(path = "/remove_readed",method = RequestMethod.POST)
    public @ResponseBody RemoveReadedMap remove_readed(@RequestBody MsgId msgId){
        return messageService.remove_readed(msgId.getMsg_id(),msgId.getToken());
    }

    @RequestMapping(path = "/restore",method = RequestMethod.POST)
    public @ResponseBody RestoreMap restore(@RequestBody MsgId msgId){
        return messageService.restore(msgId.getMsg_id(),msgId.getToken());
    }

    @RequestMapping(path = "/count",method = RequestMethod.GET)
    public @ResponseBody UnReadCountMap count(@RequestParam("token") String token ){
        return messageService.count(token);
    }


}
